package com.kingyun.gpsinspection.purificationservice.services.som.innerservice.impl;

import com.cqhilink.api.common.utils.UniqueUtil;
import com.kingyun.gpsinspection.purificationservice.dao.mapper.som.AppErrorLogMapper;
import com.kingyun.gpsinspection.purificationservice.dao.mapper.som.AppVersionMapper;
import com.kingyun.gpsinspection.purificationservice.dao.mapper.som.ItemValueMapper;
import com.kingyun.gpsinspection.purificationservice.dao.mapper.som.OpcMapper;
import com.kingyun.gpsinspection.purificationservice.facade.model.som.AppErrorLog;
import com.kingyun.gpsinspection.purificationservice.facade.model.som.AppVersion;
import com.kingyun.gpsinspection.purificationservice.facade.model.som.ItemValue;
import com.kingyun.gpsinspection.purificationservice.facade.model.som.Opc;
import com.kingyun.gpsinspection.purificationservice.facade.service.som.FacadeAppService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by yangcs on 2017/4/24.
 */
public class FacadeAppServiceImpl implements FacadeAppService {

    @Autowired
    private AppVersionMapper appVersionMapper;
    @Autowired
    private AppErrorLogMapper appErrorLogMapper;
    @Autowired
    private OpcMapper opcMapper;
    @Autowired
    private ItemValueMapper itemValueMapper;

    /**
     * 新增错误日志
     *
     * @param appErrorLog
     * @return
     */
    @Override
    public int insertErrorLog(AppErrorLog appErrorLog) {
        appErrorLog.setLogId(UniqueUtil.uuid());
        return appErrorLogMapper.addErrorLog(appErrorLog);
    }

    /**
     * 检查版本更新
     *
     * @return
     */
    @Override
    public AppVersion checkUpdate() {
        return appVersionMapper.checkUpdate();
    }

    /**
     * 查询opc列表
     *
     * @param userId
     * @param limit
     * @param offset
     * @param keyword
     * @return
     */
    @Override
    public List<Opc> queryList(String userId, int limit, int offset, String keyword) {
        Map map = new HashMap<>();
        map.put("userId", userId);
        map.put("limit", limit);
        map.put("offset", offset);
        map.put("keyword", keyword);
        return opcMapper.queryList(map);
    }

    /**
     * 查询最近12条实时数据
     *
     * @param dataSrcItemId
     * @return
     */
    @Override
    public List<ItemValue> queryList(String dataSrcItemId) {
        return itemValueMapper.queryList(dataSrcItemId);
    }
}
